<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>

<body>
    <div id="app">

    </div>
    <script type="text/babel">
    // 子组件需要一个根组件 通过this.props.name  
    class Clock extends React.Component{
        constructor(props){
            super(props);
            this.state={
                date:new Date()
            }
        };
        componentDidMount(){
            this.timer = setInterval(()=>{
                // vue中这么做 react不行 this.state.date = new Date();
                // react 唯一的修改参数的值就是通过setState
                this.setState({
                    date:new Date()
                })

            },1000)
        }
        componentWillUnmount(){
            clearInterval(this.timer)
        }

        render(){
            // name是通过props进行传递，date是自有的state进行定义，相当与vue中的data
            return (
                <div>
                    <p>你好{this.props.name}</p>
                    <p>{this.state.date.toString()}</p>
                </div>
            )
        }
    }
   
    var ele =(
        <div>
            <Clock name="时钟"/>    
   
        </div>
    );
        
        ReactDOM.render(
            ele,
            document.getElementById("app")
        )
       

    </script>
</body>

</html>